package org.example.conference_management.controller;


import jakarta.annotation.Resource;
import jakarta.websocket.server.PathParam;
import org.apache.tomcat.util.net.openssl.ciphers.Authentication;
import org.example.conference_management.pojo.R;
import org.example.conference_management.service.Admin_service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private AdminService adminService;
    private final ConfigurableApplicationContext context;
    @Autowired
    public AdminController(ConfigurableApplicationContext context) {
        this.context = context;
    }
    //TODO 会议审核

    @GetMapping("/selectUnReviewConferenceAll")
    public R selectUnReviewConferenceAll(){
        return adminService.SelectUnReviewConferenceAll();
    }

    @GetMapping("/conferenceReview")
    public R conferenceReview(@PathParam("conference_id") int conference_id){
        return adminService.ConferenceReview(conference_id);
    }
@GetMapping("/selectAll")
public R selectAll (){
        return adminService.selectconfAll();
}
    //TODO 用户管理
    @GetMapping("/selectUserAll")
    public R selectUserAll(){
        return adminService.selectUserAll();
    }

    //TODO 1.修改用户权限

    @GetMapping("/alterUserPower")
    public R alterUserPower(@PathParam("user_id")int user_id){
        return adminService.alterUserPower(user_id);
    }

    //TODO 2.删除用户

    @GetMapping("/deleteUser")
    public R deleteUser(@PathParam("user_id")int user_id){return adminService.deleteUser(user_id);}

    //TODO 系统管理 (发布维护公告)
    @PostMapping("/system/shutdown")
    public String shutdownSystem() {

        // 在新线程中执行关机（避免阻塞当前请求）
        new Thread(() -> {
            try {
                Thread.sleep(300); // 给响应返回留出时间
                context.close();   // 关闭应用
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }).start();

        return "系统正在关闭维护，请稍后重启...";
    }
}

